#include <gtest/gtest.h>
#include "MarsRover.h"
#include <iostream>
using namespace std;
using namespace MR;
int MR::MarsRoverBase::NORTH = 0;
int MR::MarsRoverBase::EAST = 1;
int MR::MarsRoverBase::SOURTH = 2;
int MR::MarsRoverBase::WEST = 3;
TEST(MarsRover,init){
	//创建 火星车对象
	MarsRover Mr;
	
	MarsRover::Status initStatus=  Mr.init(1,2,MarsRover::NORTH);
	cout<<"["<<initStatus.x<<","<<initStatus.y<<"]"<<":->"<<initStatus.direction<<endl;
	ASSERT_EQ(initStatus.x,1);
	ASSERT_EQ(initStatus.y,2);
	ASSERT_EQ(initStatus.direction,MarsRover::NORTH);
}

TEST(MarsRover,Move_turn_left_right){
	MarsRover Mr;
	
	MarsRover::Status initStatus=  Mr.init(1,2,MarsRover::NORTH);
	cout<<"["<<initStatus.x<<","<<initStatus.y<<"]"<<":->"<<initStatus.direction<<endl;

	MarsRover::Status curStatus = Mr.turnLeft();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(curStatus.x,1);
	ASSERT_EQ(curStatus.y,2);
	ASSERT_EQ(curStatus.direction,MarsRover::WEST);

	curStatus = Mr.turnLeft();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(curStatus.x,1);
	ASSERT_EQ(curStatus.y,2);
	ASSERT_EQ(curStatus.direction,MarsRover::SOURTH);

	curStatus = Mr.turnLeft();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(curStatus.x,1);
	ASSERT_EQ(curStatus.y,2);
	ASSERT_EQ(curStatus.direction,MarsRover::EAST);

	curStatus = Mr.turnLeft();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(curStatus.x,1);
	ASSERT_EQ(curStatus.y,2);
	ASSERT_EQ(curStatus.direction,MarsRover::NORTH);

	curStatus = Mr.turnRight();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(curStatus.x,1);
	ASSERT_EQ(curStatus.y,2);
	ASSERT_EQ(curStatus.direction,MarsRover::EAST);

	curStatus = Mr.turnRight();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(curStatus.x,1);
	ASSERT_EQ(curStatus.y,2);
	ASSERT_EQ(curStatus.direction,MarsRover::SOURTH);

	curStatus = Mr.turnRight();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(curStatus.x,1);
	ASSERT_EQ(curStatus.y,2);
	ASSERT_EQ(curStatus.direction,MarsRover::WEST);

	curStatus = Mr.turnRight();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(curStatus.x,1);
	ASSERT_EQ(curStatus.y,2);
	ASSERT_EQ(curStatus.direction,MarsRover::NORTH);
}



class TestMove{
public:
	TestMove(MarsRover::Status left):left(left){}
	~TestMove(){}
	bool operator()(int x, int y,int direction){
		MarsRover::Status right(direction,x,y);
		return left == right;
	}
	MarsRover::Status & left;
};




TEST(MarsRover,Move_forward_back){
	MarsRover Mr;
	
	MarsRover::Status initStatus=  Mr.init(1,2,MarsRover::NORTH);
	cout<<"["<<initStatus.x<<","<<initStatus.y<<"]"<<":->"<<initStatus.direction<<endl;

	MarsRover::Status curStatus;
	
	curStatus = Mr.moveForward();
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(true,TestMove(curStatus)(1,3,MarsRover::NORTH));

	curStatus = Mr.moveForward(10);
	cout<<"["<<curStatus.x<<","<<curStatus.y<<"]"<<":->"<<curStatus.direction<<endl;
	ASSERT_EQ(true,TestMove(curStatus)(1,13,MarsRover::NORTH));
}













